﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Jayden.Windows.Startup
{
	public partial class MainForm : Form
	{
		private NotifyIcon m_TrayIcon;
		private ContextMenu m_TrayMenu;

		public MainForm()
		{
			InitializeComponent();

			// Create a simple tray menu with only one item.
			m_TrayMenu = new ContextMenu();
			m_TrayMenu.MenuItems.Add("Exit", OnExit);
			m_TrayMenu.MenuItems.Add("Open", OnOpen);

			// Create a tray icon. In this example we use a
			// standard system icon for simplicity, but you
			// can of course use your own custom icon too.
			m_TrayIcon = new NotifyIcon();
			m_TrayIcon.Text = "Jayden Startup";
			m_TrayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
			m_TrayIcon.MouseDoubleClick += new MouseEventHandler(OnOpen);

			// Add menu to tray icon and show it.
			m_TrayIcon.ContextMenu = m_TrayMenu;
			m_TrayIcon.Visible = true;
		}
		protected override void OnLoad(EventArgs e)
		{
			Visible = false; // Hide form window.
			ShowInTaskbar = false; // Remove from taskbar.

			base.OnLoad(e);
		}

		protected override void OnClosing(CancelEventArgs e)
		{
			base.OnClosing(e);

			if (!e.Cancel)
			{
				e.Cancel = true;
				Visible = false;
			}
		}

		private void OnExit(object sender, EventArgs e)
		{
			Application.Exit();
		}

		private void OnOpen(object sender, EventArgs e)
		{
			Visible = true;
		}

		private void OnOpen(object sender, MouseEventArgs e)
		{
			Visible = true;
		}

		protected override void Dispose(bool isDisposing)
		{
			if (isDisposing)
			{
				// Release the icon resource.
				m_TrayIcon.Dispose();
			}

			DisposeComponents(isDisposing);
		}
	}
}
